using System.Collections.Generic;
using UnityEngine;

namespace Battle
{
	public class BattleMap: Map
	{
		public const int RoadCost = 1;
		public const int PlainCost = 5;
		public const int RiverCost = 99;
		public AStar PathFinder;
		public BattleNode[] mapData;
		public int[] river;
		public int[] roads;
		
		public override void Init (MapInput input)
		{
			base.Init (input);
			PathFinder = new AStar(this);

			mapData = new BattleNode[this.Count()];
			for(int i=0;i<mapData.Length;++i)
			{
				mapData[i] = new BattleNode();
			}
			
			List<int> roads = input.Roads;
			this.roads = roads.ToArray();
			for(int i=0;i<roads.Count;++i)
			{
				mapData[roads[i]].terrain = TerrainType.Road;
			}
			
			
			List<int> river = input.River;
			this.river = river.ToArray();
			for(int i=0;i<river.Count;++i)
			{
				mapData[river[i]].terrain = TerrainType.River;
			}
			
		}

		public override int Cost(Node from, Node to, Actor a)
		{
			for(int i=0;i<roads.Length;++i)
			{
				if(roads[i] == to)
					return RoadCost;
			}
			for(int i=0;i<river.Length;++i)
			{
				if(river[i] == to)
					return RiverCost;
			}
			
			return PlainCost;
		}
		
		public override int Heuristic (Node goal, Node next, Actor actor)
		{
			return Mathf.Abs(X(goal)-X(next))+Mathf.Abs(Y(goal)-Y(next));
		}
	}
}
